package org.example.game;

import org.example.game.entity.Tank;

import javax.swing.*;
import java.awt.*;

public class StartPanel extends JPanel {
    private TankGame tankGame;
    
    public StartPanel(TankGame game) {
        this.tankGame = game;
        setLayout(new GridBagLayout());
        initComponents();
    }
    
    private void initComponents() {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(10, 10, 10, 10);
        
        // 标题
        JLabel titleLabel = new JLabel("坦克大战", SwingConstants.CENTER);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 48));
        add(titleLabel, gbc);
        
        // 游戏模式选择
        String[] modes = {"单人模式", "双人模式", "人机模式", "联网模式"};
        JComboBox<String> modeSelect = new JComboBox<>(modes);
        add(modeSelect, gbc);
        
        // 游戏设置面板
        JPanel settingsPanel = new JPanel(new GridLayout(2, 2, 10, 10));
        settingsPanel.setBorder(BorderFactory.createTitledBorder("游戏设置"));
        
        // 坦克速度设置
        JSlider speedSlider = new JSlider(1, 10, 5);
        speedSlider.setMajorTickSpacing(1);
        speedSlider.setPaintTicks(true);
        speedSlider.setPaintLabels(true);
        JPanel speedPanel = new JPanel(new BorderLayout());
        speedPanel.add(new JLabel("坦克速度: "), BorderLayout.WEST);
        speedPanel.add(speedSlider, BorderLayout.CENTER);
        settingsPanel.add(speedPanel);
        
        add(settingsPanel, gbc);
        
        // 开始游戏按钮
        JButton startButton = new JButton("开始游戏");
        startButton.addActionListener(e -> {
            TankGame.GameMode selectedMode = TankGame.GameMode.values()[modeSelect.getSelectedIndex()];
            Tank.TANK_SPEED = speedSlider.getValue();
            tankGame.startGame(selectedMode);
        });
        add(startButton, gbc);
    }
} 